<%@ page import='java.sql.ResultSet' %>
<%@ page import='forum.*' %>
<%@ page import='java.util.List' %>
<%@ page import='forum.dao.*' %>
<%@taglib uri="/WEB-INF/tlds/label.tld" prefix="lutag" %>

<% String sessionUsername = (String) session.getAttribute("username"); %>
<% String sessionType = (String) session.getAttribute("type"); %>

<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">

<html>
<head>
    <title><lutag:label name="title"/></title>
    <lutag:link href="css/forum.css"/>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <script src="../editor/kindeditor.js"></script>
    <script>
        KE.show({
           id : 'myarea'
        });
	</script>
</head>
<jsp:include page="./include/body.jsp" flush="true"/>

<table width="100%" height="20" border="0" cellpadding="1" cellspacing="1">
    <tr>
        <td height="20" valign="top" class="pathBar">
            <a href="index.jsp" class="pathBarLink"><lutag:label name="myforum"/></a>
        </td>
    </tr>
</table>
<table cellspacing="0" cellpadding="0" width="100%" class="table_bg" border="0" align="center">
    <tr>
        <td>
            <table cellspacing="1" cellpadding="4" width="100%" border="0">
                <tr class="tr_bg">
                    <td align="middle" colspan="1" class="tr_bg">
                        <span class="span_style">
                            <b><lutag:label name="forums"/></b>
                        </span>
                    </td>
                    <td align="middle" colspan="1" class="tr_bg">
                        <span class="span_style">
                        <b><lutag:label name="topic"/></b>
                        </span>
                    </td>
                    <td align="middle" colspan="1" class="tr_bg">
                        <span class="span_style">
                            <b><lutag:label name="reply"/></b>
                        </span>
                    </td>
                    <td align="middle" colspan="1" class="tr_bg">
                        <span class="span_style">
                        <b><lutag:label name="lastpostinfo"/></b>
                        </span>
                    </td>
                        <% if(sessionType.equals("Admin")){ %>
                    <td align="middle" colspan="1" class="tr_bg">
                        <span class="span_style">
                        <b><lutag:label name="delforum"/></b>
                        </span>
                    </td>
                </tr>
                        <% }

							List<ForumBean> list = (List<ForumBean>)request.getAttribute("forums");

							if(list != null && list.size() > 0){
                            for(ForumBean bean : list){
                                String forum_id = bean.getForum_id() + "";
                                String title = bean.getTitle();
                                String info = bean.getForum_info();
                                String topics = bean.getTopics();
                                String forumReplies = bean.getForumReplies();
                                String lastPostInfo = bean.getLastPostInfo();
                        %>
                <tr bgcolor=#ffffff>
                    <td align="left" valign="top" width="0">
                        <span class="span_style">
                            <a href="./index.jsp?page=thread&forum_id=<%= forum_id %>" class="forumLink"><%= title %>
                            </a>
                            <br>
                            <span class="forumInfo"><%= info %></span>
                        </span>
                    </td>
                    <td align="left" valign="top" width="0">
                        <span class="span_style">
                            <span class="forumTopics"><%= topics %></span>
                        </span>
                    </td>
                    <td align="left" valign="top" width="0">
                        <span class="span_style">
                            <span class="forumReplies"><%= forumReplies %></span>
                        </span>
                    </td>
                    <td align="left" valign="top" width="0">
                        <span class="span_style">
                            <span class="forumPostInfo"><%= lastPostInfo %></span>
                        </span>
                    </td>
		   <% if(sessionType.equals("Admin")){ %>
                    <td align="left" valign="top" width="0">
                        <span class="span_style">
                            <a href="../servlet/Forum.delete?forum_id=<%= forum_id %>" class="forumDelete"><lutag:label
                                    name="delete"/></a>
                        </span>
                    </td>
            <%
                    }
                }
							}
            %>
                </tr>

                <tr class="table_bg">
                    <td align="left" colspan="5" class="tr_bg">
                        <span class="span_style">
                            <b>&nbsp;</b>
                        </span>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<br>
    <% if(sessionType.equals("Admin")){ %>
<table cellspacing="0" cellpadding="0" width="100%" class="table_bg" border="0" align="center">
    <tr>
        <td>
            <table cellspacing="1" cellpadding="4" width="100%" border="0">
                <tr class="tr_bg">
                    <td align="left" colspan="2" class="tr_bg">
                        <span class="span_style">
                            <b><lutag:label name="addforum"/></b>
                        </span>
                    </td>
                <tr bgcolor=#ffffff>
                    <td align="left" valign="top" width="200">
                        <span class="span_style">
                                <form action="../servlet/Forum.add" method=POST name=form>
                                    <lutag:label name="str_title"/><lutag:label name="colon"/><br>
                                    <input type="text" name="title" size="62" maxlength="60"><br>
                                    <lutag:label name="foruminfo"/><lutag:label name="colon"/><br>
                                    <textarea name="forum_info" id="myarea"  cols="100" rows="10" style="width:700px;height:300px;"></textarea><br>
                                    <input type="submit" value="Add Forum"><br>
                                </form>
                         </span>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
    <% 
    }%>
<jsp:include page="./include/footer.jsp" flush="true"/>